package ar.edu.utn.frba.dds.tp.transformers;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.uqbar.arena.bindings.Transformer;

import ar.edu.utn.frba.dds.tp.code.dateParser.FormatoSimple;

public class StringToFechaTransformer implements Transformer<Date, String> {

	@Override
	public Class<Date> getModelType() {
		return Date.class;
	}

	@Override
	public Class<String> getViewType() {
		return String.class;
	}

	@Override
	public String modelToView(Date date) {
		if (date==null)
			return "";
		return new SimpleDateFormat("dd/MM/yyyy").format(date);
	}

	@Override
	public Date viewToModel(String s) {
		
		if(s.length() == 0)
			return null;
		
		return new FormatoSimple("dd/MM/yyyy").parse(s);
	}
	
}
